package com.job.client.common.rabbitmqConfig;

import com.job.client.model.rabbitmq.DraftConstant;
import com.job.client.model.rabbitmq.MessageConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
/*
 * 用户消息队列
 * */
public class RabbitmqMessageConfig {
    @Bean
    public Exchange EXCHANGE_MESSAGE(){
        return ExchangeBuilder
                .directExchange(MessageConstant.EXCHANGE_MESSAGE) // 直连交换机，根据key匹配
                .durable(true).build();  // 持久化
    }

    @Bean
    public Queue QUEUE_MESSAGE_AVATAR(){
        return new Queue(MessageConstant.QUEUE_MESSAGE_AVATAR);
    }

    @Bean
    public Binding BINDING_QUEUE_MESSAGE_AVATAR(Queue QUEUE_MESSAGE_AVATAR, Exchange EXCHANGE_MESSAGE){
        return BindingBuilder.bind(QUEUE_MESSAGE_AVATAR)
                .to(EXCHANGE_MESSAGE)
                .with(MessageConstant.ROUTINGKEY_AVATAR).noargs();
    }

    @Bean
    public Queue QUEUE_MESSAGE_COMPANY(){
        return new Queue(MessageConstant.QUEUE_MESSAGE_COMPANY);
    }

    @Bean
    public Binding BINDING_QUEUE_MESSAGE_COMPANY(Queue QUEUE_MESSAGE_COMPANY, Exchange EXCHANGE_MESSAGE){
        return BindingBuilder.bind(QUEUE_MESSAGE_COMPANY)
                .to(EXCHANGE_MESSAGE)
                .with(MessageConstant.ROUTINGKEY_COMPANY).noargs();
    }
    @Bean
    public Queue QUEUE_MESSAGE_POSTS(){
        return new Queue(MessageConstant.QUEUE_MESSAGE_POSTS);
    }

    @Bean
    public Binding BINDING_QUEUE_MESSAGE_POSTS(Queue QUEUE_MESSAGE_POSTS, Exchange EXCHANGE_MESSAGE){
        return BindingBuilder.bind(QUEUE_MESSAGE_POSTS)
                .to(EXCHANGE_MESSAGE)
                .with(MessageConstant.ROUTINGKEY_POSTS).noargs();
    }
}
